package com.wms.system.service.impl.wcs;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wms.common.utils.Assert;
import com.wms.system.domain.wcs.PackingListSon;
import com.wms.system.mapper.wcs.PackingListSonMapper;
import com.wms.system.service.wcs.IPackingListSonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

@Service
public class PackingListSonServiceImpl implements IPackingListSonService {

    @Autowired
    private PackingListSonMapper packingListSonMapper;

    @Override
    public List<PackingListSon> queryListByOrderCode(String orderCode) {
        Assert.isNotBlank(orderCode,"父级订单号不可为空");
        List<PackingListSon> dataList = packingListSonMapper.selectList(new LambdaQueryWrapper<PackingListSon>()
                .eq( PackingListSon::getOrderCode, orderCode)
        );
        dataList.sort(Comparator.comparing(x->Integer.parseInt(x.getSerialNumber())));
        return dataList;
    }

    @Override
    public void insert(PackingListSon packingListSon){
        packingListSon.setId(null);
        packingListSon.setCreatedTime(LocalDateTime.now());
        packingListSon.setUpdateTime(LocalDateTime.now());
        packingListSonMapper.insert(packingListSon);
    }

    @Override
    public void update(PackingListSon packingListSon){
        packingListSon.setUpdateTime(LocalDateTime.now());
        packingListSonMapper.updateById(packingListSon);
    }

    @Override
    public PackingListSon detail(PackingListSon packingListSon){
        return packingListSonMapper.selectById(packingListSon.getId());
    }

    @Override
    public void delete(Long[] ids){
        packingListSonMapper.deleteBatchIds(Arrays.asList(ids));
    }
}
